@model Mod.Training.Models.ItemListPart
@using Orchard.ContentManagement;

@{ 
    Script.Require("jQuery");
    var count = 0;
    if(Model.Items != null) {
        count = Model.Items.Count();
    }
}

<fieldset>
    <legend>@T("ItemListPart settings")</legend>
    
    @for(int i = 0; i < count; i++) {
        @Html.EditorFor(m => Model.Items[i])
    }

    <a href="/Mod.Training/Training/NewItem" id="addItem">Add another...</a>

    <div id="newitems"></div>

</fieldset>

@using(Script.Foot()) {
    <script type="text/javascript">
        var length = @count ;


        $("#addItem").click(function () {
            $.ajax({
                url: this.href,
                cache: false,
                //data: { name: "Items", length: length },
                success: function (html) { 
                    $("#newitems").append(html); 
                    
                    //$("#Items_" + length + "__Name").attr('name', "Items[" + length + "].Name");
                    //$("#Items_" + length + "__Age").attr('name', "Items[" + length + "].Age");

                    length++;
                }
            });
            return false;
        });
    </script>
}